<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">

</style>
<div class="page-header">
	<h1>
		健康预警
		<small>
			<a href="<?=admin_url('school/health_warn_edit')?>" class="blue ml10">
				<i class="ace-icon fa fa-plus"></i> 添加预警字段
			</a>
		</small>
	</h1>
</div>
<div class="col-xs-12 content-filter">
	<!-- 表格 -->
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>预警字段</th>
				<th>预警值</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){
		var table = $('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('school/get_health_warn_list')?>',
			"columns": [
	            {"data": "key"},
	            {"data": "value"},
	            {"data": "createtime"},
	            {"data": function(ret){
					var action = '';
						action += '<a class="mr20" href="<?=admin_url('school/health_warn_edit')?>/'+ ret.id +'"><i class="fa fa-edit"></i> 修改</a>';
						action += '<a class="text-danger delete-warn" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.key + '><i class="fa fa-times"></i> 删除</a>';
	                return action;
	            }},
			]
		});
		// 删除教师
		$("body").on('click', '.delete-warn', function() {
			var id = $(this).data('id');
			var title = $(this).data('title');
			var posturl = "<?= admin_url("school/delete_health_warn_action") ?>";
			var data = {
				'id': id
			};
			layer.confirm('确定删除字段：' + title + '？', { title:"提示", offset: '160px' }, function(){
				ajax_post(posturl, data, function() {
					// 刷新页面
					window.location.href = "<?= admin_url('school/health_warn') ?>";
				});
			});
		});
	})
</script>